<?php
include "header.php";
include "./lib/func.php";
include "./lib/config.php";

if (($user = isLogin()) == false){
    header("location:index.php");
}

/**
 * 微博关注
 * following 我的关注  followed 关注我的
 * [示例]
 * aid关注bid
 * following 关注表  following:aid(bid)
 * followed  被关注表 followed:bid(aid)
 *
 * 1.获取地址栏的u参数用户名
 * 2，查询UID
 * 3，查询UID是否在我的following[我的关注表]里
 */

$uid = trim(getGet('uid'));
$follow = trim(getGet('f'));

if (!$uid){
    showError('传入的uid不合法');
}
if (!$follow){
    showError('传入的关注参数不合法');
}

$redis = connentRedis(Config::REDISHOST, Config::PORT);
if ($follow == 1) {
    $redis->sAdd('following:' . $user['userid'], $uid);
    $redis->sAdd('followed:' . $uid, $user['userid']);
}else{
    $redis->sRem('following:'. $user['userid'], $uid);
    $redis->sRem('followed:'. $uid, $user['userid']);
}

$uname = $redis->get('user:userid:'. $uid. ':username');

header("location:profile.php?u=". $uname);


include "footer.php";